/**
 * @file Border.as
 *  选择框，按←→键，轮流切换位置
 * @author db0@qq.com
 * @version 1.0.1
 * @date 2017-10-31
 */
package zhuhai
{
	import flash.display.Sprite;
	import flash.events.Event;
	public class Border extends Sprite
	{

		//当前的位置序号
		public static var index:int = 0;
		public function Border()
		{
			addEventListener(Event.ADDED_TO_STAGE,init);

			MyKey.main.addEventListener(MyKey.LEFT,left);
			MyKey.main.addEventListener(MyKey.RIGHT,right);
		}

		private function left(e:Event):void
		{
			if(!visible || !parent.visible)
				return;
			if(index>0)
				--index;

			toIndex();
		}
		private function right(e:Event):void
		{
			if(!visible || !parent.visible)
				return;
			if(index<5)
				++index;

			toIndex();
		}
		private function toIndex():void
		{
			var tx:int = 0;
			var ty:int = Main.header.height;
			var tw:int = Main.stageWidth/3;
			var th:int = (Main.stageHeight-ty)/2;
			x = tx + (index%3)*tw;
			y = ty + int(index/3)*th;
		}

		private function init(e:Event):void
		{
			with(graphics)
			{
				clear();
				lineStyle(4,0xff0000);
				drawRect(0,0,Main.stageWidth/3,(Main.stageHeight-Main.header.height)/2);
				endFill();
			}
			toIndex();
		}

	}
}
